package mysql

import "gorm.io/gorm"

type Order struct {
	gorm.Model
	UserId      int     `gorm:"type:int;not null;comment:'用户Id'"`
	GoodsId     int     `gorm:"type:int;not null;comment:'商品Id'"`
	OrderSn     string  `gorm:"type:varchar(36);not null;comment:'订单编号'"`
	Amount      float64 `gorm:"type:double(10,2);not null;comment:'商品总价'"`
	Num         int     `gorm:"type:int;not null;comment:'购买数量'"`
	GoodsTitle  string  `gorm:"type:varchar(50);not null;comment:'商品标题'"`
	GoodsImage  string  `gorm:"type:varchar(255);not null;comment:'商品图片'"`
	OrderStatus int     `gorm:"type:int;not null;comment:状态:1-已支付,2-未支付,3-待支付,4-已完成"`
	Payment     int     `gorm:"type:int;not null;comment:状态:1-支付宝,2-微信"`
}

func (o *Order) Create() error {
	return DB.Create(&o).Error
}

func (o *Order) OrderList(page, pageSize int) (order []Order, err2 error) {
	DB.Offset((page - 1) * pageSize).Limit(pageSize).Find(&order)
	return
}
